﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_DAL;
using Zor_Modes;
using Zor_Tools;

namespace Zor_Bll
{
     public class HouseRental_Bll<T> where T : class
    {

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(dynamic Model, int index, out int TotalCount, string where)
        {
            var sqlSurch = string.Empty;
            if (Model.Bd_Name != null)
            {
                sqlSurch += " Bd_Name like '%" + Model.Bd_Name + "%' and ";
            }
            if (Model.Uim_Name != null)
            {
                sqlSurch += " Uim_Name like '%" + Model.Uim_Name + "%' and ";
            }
            if (Model.Hs_Number != 0)
            {
                sqlSurch += " Hs_Number like '%" + Model.Hs_Number + "%' and ";
            }
            if (Model.NatPer_Name != null)
            {
                sqlSurch += "NatPer_Name like '%" + Model.NatPer_Name + "%' and ";
            }
            if (Model.Hs_Proportion != 0)
            {
                sqlSurch += " Hs_Proportion like '%" + Model.Hs_Proportion + "%' and ";
            }
            if (Model.NatSex != null)
            {
                sqlSurch += "NatSex = '" + Model.NatSex + "' and ";
            }
            if (Model.Nature != null)
            {
                sqlSurch += "Nature = '" + Model.Nature + "' and ";
            }
            if (Model.HousUse != null)
            {
                sqlSurch += "HousUse = '" + Model.HousUse + "' and ";
            }
            if (Model.Attribute != null)
            {
                sqlSurch += "Attribute = '" + Model.Attribute + "' and ";
            }
            if (Model.Tenant_Name != null)
            {
                sqlSurch += "Tenant_Name like '%" + Model.Tenant_Name + "%' and ";
            }
            if (Model.Lease_StartTime != null)
            {
                int st = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Lease_StartTime.ToString()));
                sqlSurch += "Lease_StartTime = " + st + " and ";
            }
            if (Model.Lease_EndTime != null)
            {
                int et = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Lease_EndTime.ToString()));
                sqlSurch += "Lease_EndTime = " + et + " and ";
            }
            sqlSurch += " Dt_Id = " + RequestSession.GetSessionUser().DT_Id + "";
            return PagerHelp<T>.GetPagerList(index, "V_HouseRental", "Bd_Name", out TotalCount, sqlSurch);
        }

        /// <summary>
        /// 获取租赁管理列表（不分页）
        /// create 刘云飞 by 2017/04/06       
        /// </summary>
        /// <returns></returns>
        public static List<T> GetList(dynamic Model, string where)
        {
            var sqlSurch = string.Empty;
            if (Model.Bd_Name != null)
            {
                sqlSurch += " Bd_Name like '%" + Model.Bd_Name + "%' and ";
            }
            if (Model.Uim_Name != null)
            {
                sqlSurch += " Uim_Name like '%" + Model.Uim_Name + "%' and ";
            }
            if (Model.Hs_Number != 0)
            {
                sqlSurch += " Hs_Number like '%" + Model.Hs_Number + "%' and ";
            }
            if (Model.NatPer_Name != null)
            {
                sqlSurch += "NatPer_Name like '%" + Model.NatPer_Name + "%' and ";
            }
            if (Model.Hs_Proportion != 0)
            {
                sqlSurch += " Hs_Proportion like '%" + Model.Hs_Proportion + "%' and ";
            }
            if (Model.NatSex != null)
            {
                sqlSurch += "NatSex = '" + Model.NatSex + "' and ";
            }
            if (Model.Nature != null)
            {
                sqlSurch += "Nature = '" + Model.Nature + "' and ";
            }
            if (Model.HousUse != null)
            {
                sqlSurch += "HousUse = '" + Model.HousUse + "' and ";
            }
            if (Model.Attribute != null)
            {
                sqlSurch += "Attribute = '" + Model.Attribute + "' and ";
            }
            if (Model.Tenant_Name != null)
            {
                sqlSurch += "Tenant_Name like '%" + Model.Tenant_Name + "%' and ";
            }
            if (Model.Lease_StartTime != null)
            {
                int st = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Lease_StartTime.ToString()));
                sqlSurch += "Lease_StartTime = " + st + " and ";
            }
            if (Model.Lease_EndTime != null)
            {
                int et = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Lease_EndTime.ToString()));
                sqlSurch += "Lease_EndTime = " + et + " and ";
            }
            sqlSurch += " Dt_Id = " + RequestSession.GetSessionUser().DT_Id + "";
            return HouseRental_DAL<T>.SelectViewHouseRental(sqlSurch);
        }
    }
}
